<?php

namespace app\controller\admin;

use app\BaseController;
use app\model\ProductCode;
use think\response\Json;

class Product extends BaseController
{
    public function lst(): Json
    {
        return $this->success($this->app->make(\app\model\Product::class)->getPage());
    }
    public function save(): Json
    {
        if(!$this->request->isPost()) throw new \Exception("请求方式错误", 7001);
        return $this->success($this->app->make(\app\model\Product::class)->updateOrAdd());
    }

    public function detail(): Json
    {
        return $this->success($this->app->make(\app\model\Product::class)->detail());
    }

    public function autoCoupon(): Json
    {
        if(!$this->request->isPost()) throw new \Exception("请求方式错误", 7001);
        return $this->success($this->app->make(ProductCode::class)->autoCoupon());
    }

    public function importCoupon(): Json
    {
        if(!$this->request->isPost()) throw new \Exception("请求方式错误", 7001);
        return $this->success($this->app->make(ProductCode::class)->importCoupon());
    }

    public function delete(): Json
    {
       if(!$this->request->isDelete()) throw new \Exception("请求方式错误", 7001);
       return $this->success($this->app->make(\app\model\Product::class)->delProduct());
    }

    public function searchProduct(): Json
    {
        return $this->success($this->app->make(\app\model\Product::class)->searchProduct());
    }

    public function setStock(): Json
    {
        if(!$this->request->isPost()) throw new \Exception("请求方式错误", 7001);
        return $this->success($this->app->make(\app\model\ProductAttr::class)->setStock());
    }
}
